package com.zsule.service.impl.manager;

import java.util.List;

import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import com.zsule.entity.PageEntity;
import com.zsule.entity.manager.Manager;
import com.zsule.frameworks.mongodb.service.MongoAbstractService;
import com.zsule.service.manager.IManagerService;

@Service("managerService")
public class ManagerServiceImpl extends MongoAbstractService<Manager> implements IManagerService {

	@Override
	public Manager getUserByNameAndPwd(String name, String pwd) {
		return findOne(new Query(Criteria.where("loginName").is(name).and("loginPwd").is(pwd).and("status").ne(Manager.DELETE_STATUS)));
	}

	@Override
	public List<Manager> getManagerPage(Manager manager, PageEntity page) {
		Query query = new Query(Criteria.where("status").ne(Manager.DELETE_STATUS));
		query.with(new Sort(Direction.DESC,"createTime"));
		query.skip(page.getStartRow()).limit(page.getPageSize());
		return findList(query);
	}

}
